//
//  MyLocation.m
//  TelethonMobile
//
//  Created by Cyril ALIX on 03/12/11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "MyLocation.h"

@implementation MyLocation

@synthesize locationManager;
@synthesize longitude;
@synthesize latitude;
@synthesize delegate;

- (id)initWithDelegate:(id)inDelegate {
	self = [super init];
    
	if(self != nil) {
        
        self.delegate = inDelegate;
        
        self.locationManager = [[[CLLocationManager alloc] init] autorelease];
        NSAssert(self.locationManager != nil, @"Erreur location manager null");
        self.locationManager.delegate = self;
        self.locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
        self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers; //kCLLocationAccuracyBest;
        [self.locationManager startUpdatingLocation];
        
	}
    
	return self;
}

- (void)dealloc {
    NSLog(@"Dealloc");
	[self.locationManager release];
	[super dealloc];
}


#pragma mark -
#pragma mark delegate

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
               delegate:(id)theDelegate
{
    NSLog(@"Coucou");
    longitude = newLocation.coordinate.longitude;
    latitude = newLocation.coordinate.latitude;
    [locationManager stopUpdatingLocation];
    [self.delegate isDoneUpdatingLatitude:latitude longitude:longitude];
}


- (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"On a une erreru %@", error);
}

@end
